package me.youline.dataServer.service.front;

import java.io.IOException;
import java.io.InputStream;

import me.youline.dataServer.exception.InvalidFileFormatException;
import me.youline.dataServer.service.MimeConfig;

import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

@Component
public class UserAccountInfoControllerHelper {
	
	public InputStream getValidUploadAvatar(MultipartRequest fileRequest) throws IOException{
		MultipartFile uploadFile = fileRequest.getFile("avatarPic");
		if(uploadFile != null){
			if(! MimeConfig.ALLOW_IMAGE_TYPE.contains(uploadFile.getContentType())){
				throw new InvalidFileFormatException("invalid upload avatar");
			}
			return uploadFile.getInputStream();
		}
		return null;
	}
}
